package cn.wolfcode.wms.domain;

import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
public class Product {
    private Long id;

    private String name;

    private String sn;

    private BigDecimal costPrice;

    private BigDecimal salePrice;

    private String imagePath;

    private String intro;

    private Long brandId;

    private String brandName;

    public String getSmallImagePath() {
        if (StringUtils.isEmpty(imagePath)) {
            return "";
        }
        //得到图片前缀
        String prefix = this.imagePath.substring(0, this.imagePath.lastIndexOf("."));
        //得到图片后缀
        String suffix = this.imagePath.substring(this.imagePath.lastIndexOf("."));
        return prefix + "_small"+suffix;
    }

    public String getJson(){
        Map<String,Object> json =new HashMap<>();
        json.put("id",id);
        json.put("name",name);
        json.put("costPrice",costPrice);
        json.put("salePrice",salePrice);
        json.put("brandName",brandName);
        return JSON.toJSONString(json);
    }
}